﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Gollie.Ajax
{
	public class PaymentTicket : Ticket
	{
		uint customerId;
		uint cashierId;
		DateTime creationDate;

		public PaymentTicket()
			: base()
		{
			creationDate = DateTime.Now;
			Push(creationDate);
		}

		public PaymentTicket(string ticket)
			: base(ticket)
		{
			PopHash();
			this.cashierId = PopUInt32();
			this.customerId = PopUInt32();
			creationDate = PopDateTime();
		}

		public void Populate(uint customerId, uint cashierId)
		{
			this.customerId = customerId;
			this.cashierId = cashierId;

			Push(customerId);
			Push(cashierId);

			PushHash();
		}

		internal bool IsValid(uint customerId, uint cashierId)
		{
			TimeSpan span = DateTime.Now - creationDate;
			if (span.TotalSeconds > 600)
				return false;

			if (customerId != this.customerId || cashierId != this.cashierId)
				throw new TicketException("Gebruikers komen niet overeen");

			return true;
		}
	}
}